package org.footballmanager.pandafootball.system.form.impl;

import lombok.Getter;
import lombok.Setter;
import org.footballmanager.pandafootball.system.domain.FootUser;
import org.footballmanager.pandafootball.system.domain.enums.QX;
import org.footballmanager.pandafootball.system.form.SearchForm;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.io.Serializable;

@Getter
@Setter
public class FootUserSearchForm extends SearchForm implements Serializable {
    private static final long serialVersionUID = 8090668615941861547L;
    protected String name;
    protected QX qx;

    public Example buildSearchCommond() {
        Example example = new Example(FootUser.class);
        Example.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(name)) {
            criteria.andLike("name", "%" + name.trim() + "%");
            Example.Criteria criteria2 = example.createCriteria();
            criteria2.andLike("nike", "%" + name.trim() + "%");
            example.or(criteria2);
        }
        if (qx != null) {
            criteria.andEqualTo("qx", qx);
        }
        criteria.andNotEqualTo("name", "admin");
        criteria.andEqualTo("delFlag", 0);
        example.orderBy("createTime").desc();
        return example;
    }

}
